package BookReturn;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import BookDB.h2DAO;
import Loginout.UserBean;


@WebServlet("/Returnbystaff")
public class Returnbystaff extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		String bookid=req.getParameter("bookid");
		String userid=req.getParameter("userid");

		HttpSession session = req.getSession();
		UserBean UB = (UserBean) session.getAttribute("ub");

		if (UB == null) {
			resp.sendRedirect("error.html");
		} else if (UB.vaild()) {
				try {
					PrintWriter writer=resp.getWriter();
				int update=
				h2DAO.updatebook4return(bookid, userid);
				if (update>0)
					resp.sendRedirect("BookMag.jsp");
				else
					writer.print("update return book record error!");
			} catch (SQLException e) {
			
				e.printStackTrace();
			}
			
		}
		}
		
		
	}


